The following examples show the use of the EViews programming language to perform the following tasks:
Suppose that you wish to compute descriptive statistics (mean, median, etc.) for each year of your monthly data in the series IP, URATE, M1, and TB10. While EViews does not provide a built-in procedure to perform this calculation, you can use the statsby view of a series to compute the relevant statistics in two steps: first create a year identifier series, and second compute the statistics for each value of the identifier.
' tabulate descriptive statistics by year' revised for version 6.0 (3/7/2007) ' change path to program path%path = @runpathcd %path ' get workfile%evworkfile = "basics"load %evworkfile ' set samplesmpl 1990:1 @last ' create a series containing the year identifierseries year = @year ' compute statistics for each year and' freeze the output from each of the tablesfor %var ip urate m1 tb10 %name = "tab" + %var freeze({%name}) {%var}.statby(min,max,mean,med) year show {%name}next
The results are saved in tables named TABIP, TABURATE, TABM1, and TABTB10. For example, TABIP contains:
The example above
saves the values in a table. You may instead wish to place the annual values in
a vector or matrix so that they can be used in other calculations. The following
program (desc2.prg) creates a vector to hold the median values for each year,
and loops through the calculation of the median for each year:
' store descriptive statistics by year' revised for version 6.0 (3/7/2007) ' change path to program path%path = @runpathcd %path ' get workfile%evworkfile = "basics"load %evworkfile ' set samplesmpl 1990:1 @last ' create series with the year and find the maximumseries year = @year!lastyear = @max(year) ' loop over the series namesfor %var ip urate m1 tb10 ' create matrix to hold the results !numrows = ({!lastyear} - 1990 + 1) + 1 matrix({!numrows}, 7) mat{%var} ' loop over each year and compute values for !i = 1990 to !lastyear !row = {!i} - 1990 + 1 smpl if (year={!i}) mat{%var}(!row,1) = {!i} mat{%var}(!row,2) = @mean({%var}) mat{%var}(!row,3) = @med({%var}) mat{%var}(!row,4) = @min({%var}) mat{%var}(!row,5) = @max({%var}) mat{%var}(!row,6) = @stdev({%var}) mat{%var}(!row,7) = @obs({%var}) next ' compute the total values smpl 1990:1 @last mat{%var}(!numrows,1) = {!i} mat{%var}(!numrows,2) = @mean({%var}) mat{%var}(!numrows,3) = @med({%var}) mat{%var}(!numrows,4) = @min({%var}) mat{%var}(!numrows,5) = @max({%var}) mat{%var}(!numrows,6) = @stdev({%var}) mat{%var}(!numrows,7) = @obs({%var}) show mat{%var}next
Most of the output from equation or system estimation can be accessed directly using EViews regression statistics functions. This is not true of all of the output from EViews’ diagnostic tests.
If you would like to work with statistics from these views in a program, you should use the following general method that allows you to extract and store output from any object view. The basic steps in each step through the loop are:
The following subroutine uses this approach to capture the F-statistic and probability value from an omitted variables test. The subroutine OMIT_TEST cycles through the series contained in a group, testing whether the first four lags of each series are jointly significant when added to the chosen equation. The output is stored in a table.
'subroutine to test whether the first four lags of an omitted'variable are jointly significant'' eq1: name of equation object to test' g: name of group object containing a list of series to test' results: name of table object to store resultssubroutine omit_test(equation eq1, group g, table results) 'number of series in group !n = g.@count table(!n+5,3) results 'set column width of table setcolwidth(results, 1, 12) setcell(results, 1, 1, "Four lag F-test for omitted variables:", "l") setline(results, 2) results(3,2) = "F-stat" results(3,3) = "Probability" setline(results, 4) 'loop through each series in group to test for !i = 1 to !n 'get series series tmp_s = g(!i) 'run test freeze(temp_t) eq1.testadd tmp_s(-1) tmp_s(-2) tmp_s(-3) tmp_s(-4) 'store results in table results(!i+4, 1) = g.@seriesname(!i) results(!i+4, 2) = temp_t(3, 2) results(!i+4, 3) = temp_t(3, 5) 'clean up delete tmp_s delete temp_t next setline(results, !n+5)endsub
The following program uses this subroutine to carry out some tests on the data from the demo in Chapter 2, “A Demonstration” of the EViews 6 User’s Guide. Both the subroutine and the program can be found in the file OMITTED.PRG.
'read data from .xls file%path = @runpath + "demo.xls"wfopen %path 'estimate equationsmpl @allequation eq1.ls dlog(m1) c dlog(m1(-1)) dlog(m1(-2)) dlog(m1(-3)) dlog(m1(-4)) 'create group to test for omitted variablesgroup g1 dlog(gdp) dlog(rs) dlog(pr) 'declare table to store test resultstable tab1 'call subroutinecall omit_test(eq1, g1, tab1) 'display resultsshow tab1
The program produces the following output:

rollreg.prg runs a set of rolling ADF tests on the series M1 using a moving sample of fixed size. The basic techniques for working with rolling samples may be used in a variety of settings. The program stores and displays the t-statistics together with the asymptotic critical value.
' rolling ADF unit root test' run in quiet mode for slight speed up'' revised for version 6.0 (3/7/2007) ' change path to program path%path = @runpathcd %path ' get workfile%evworkfile = "basics"load %evworkfile ' set samplesmpl @all ' find size of workfileseries _temp = 1!length = @obs(_temp)delete _temp ' set fixed sample size!ssize = 50 ' initialize matrix to store resultsmatrix(!length-!ssize+1,2) adftstat ' run test regression for each subsample and' store each ar(1) coefficient' test includes constant with no lagged first differencefor !i = 1 to !length-!ssize+1 ' set rolling subsample smpl @first+!i-1 @first+!i+!ssize-2 ' estimate test regression equation temp.ls d(m1) c m1(-1) ' store t-statistic adftstat(!i,1) = temp.@tstat(2) ' 5% critical value from Davidson and MacKinnon, ' Table 20.1, page 708 adftstat(!i,2) = -2.86next ' plot graph of t-statisticfreeze(graph1) adftstat.line' set aspect ration and use line patterngraph1.option size(8,2) linepat' set legend textgraph1.setelem(1) legend(ADF t-statistic)graph1.setelem(2) legend(Asymptotic 5% critical value)' add text at top of graph%comment = "ADF t-statistic for window of " + @str(!ssize) + " obs for M1"graph1.addtext(t) {%comment}show graph1

Also, see more details on moving sample.
EViews presents regression output in tabular form, with separate columns for the coefficient values and the standard errors. For example, the output view from the equation EQ1 in the workfile BASICS.WF1 is given by:

A commonly used alternative display format places the standard errors or t-statistics, enclosed in parentheses, below the coefficient estimates. The program file REGTAB.PRG contains a subroutine which takes an equation object and creates a table with this alternative output:
' subroutine to reformat regresion output' revised for version 5.0 (3/25/2004)'' eq1: name of equation object' tab1: name of table object for output' format: digits after decimal to display'subroutine regtab(equation eq1, table tab1, scalar format) ' number of estimated parameters!ncoef =eq1.@ncoef' number of observations in estimation sample!obs=eq1.@regobs ' create temporary table with eviews estimation outputfreeze(temp_table) eq1.results ' declare a new tabletable(1,4) tab1' format tablesetcolwidth(tab1, 1, 19)setcolwidth(tab1, 2, format+6)setcolwidth(tab1, 3, 19)setcolwidth(tab1, 4, format+6) ' get original header information!line = 1while @eqna(temp_table(!line, 2), "Coefficient")=0 setcell(tab1, !line, 1, temp_table(!line, 1), "l") !line = !line +1wend setline(tab1, {!line}-1) setcell(tab1, !line, 1, "Variable", "c" )setcell(tab1, !line, 2, "Estimate","r")setcell(tab1, !line, 3, "Estimate","r")setcell(tab1,!line+1,2, "(s.e.)","r")setcell(tab1,!line+1,3, "(t-stat)","r")!line = !line + 2setline(tab1, !line)!line = !line + 1!vline = !line ' fill all of the coefficients and standard errors ' (or t-statistics)for !i = 1 to !ncoef ' get variable name %variable = temp_table(!vline-1, 1) ' write coefficients setcell(tab1, !line, 1, %variable, "c") !vline = !vline + 1 ' write coefficients !est=eq1.@coefs(!i) setcell(tab1, !line, 2, !est, "r", format ) setcell(tab1, !line, 3, !est, "r", format ) !line = !line + 1 ' compute statistics !se = sqr(eq1.@covariance(!i, !i)) !tstat = !est/!se !tprob = @tdist(!tstat, !obs-!ncoef) ' write standard errors in parenthesis setcell(tab1, !line, 2, !se, "r", format ) %str_se = tab1(!line, 2) %str_se = "(" + %str_se + ")" tab1(!line, 2) = %str_se ' write t-statistic output setcell(tab1, !line, 3, !tstat, "r", format ) %str_t = "(" + tab1(!line, 3) + ")" ' mark if significant if !tprob < .01 then %str_t = "**" + %str_t else if !tprob < .05 then %str_t = "*" + %str_t endif endif tab1(!line, 3) = %str_t ' increment line counter !line = !line + 1next setline(tab1, !line)!line = !line + 1 ' original results at bottom of tablesetcell(tab1, !line, 1, "R-squared", "l") setcell(tab1, !line, 2, eq1.@r2, "r", format )setcell(tab1, !line, 3, " Mean dependent var", "l")setcell(tab1, !line, 4, eq1.@meandep, "r", format )!line = !line + 1 setcell(tab1, !line, 1, "Adjusted R-squared", "l")setcell(tab1, !line, 2, eq1.@rbar2, "r", format )setcell(tab1, !line, 3, " S.D. dependent var", "l")setcell(tab1, !line, 4, eq1.@sddep, "r", format )!line = !line + 1 setcell(tab1, !line, 1, "S.E. of regression", "l")setcell(tab1, !line, 2, eq1.@se, "r", format )setcell(tab1, !line, 3, " Akaike info criterion", "l")setcell(tab1, !line, 4, eq1.@aic, "r", format )!line = !line + 1 setcell(tab1, !line, 1, "Sum squared resid", "l")setcell(tab1, !line, 2, eq1.@ssr, "r", format )setcell(tab1, !line, 3, " Schwarz criterion", "l")setcell(tab1, !line, 4, eq1.@schwarz, "r", format )!line = !line + 1 setcell(tab1, !line, 1, "Log likelihood", "l")setcell(tab1, !line, 2, eq1.@logl, "r", format )setcell(tab1, !line, 3, " F-statistic", "l")setcell(tab1, !line, 4, eq1.@f, "r", format )!line = !line + 1 setcell(tab1, !line, 1, "Durbin-Watson stat", "l")setcell(tab1, !line, 2, eq1.@dw, "r", format)setcell(tab1, !line, 3, " Prob(F-statistic)", "l")setcell(tab1, !line, 4, @fdist(eq1.@f,(!ncoef-1),(!obs-!ncoef)), "r", format)!line = !line + 1setline(tab1, !line) endsub
To call the subroutine, you can open the program REGRUN.PRG, which contains the following commands:
' formatting regression output table' revised for version 6.0 (3/7/2007) ' include subroutine fileinclude regtab.prg 'change path to program path%path = @runpathcd %path ' load workfileload basics ' declare table to store outputtable tab1 ' call subroutine call regtab(eq1, tab1, 3) show tab1
The first argument to the REGTAB subroutine is the equation object, the second is the table into which you wish to place the results, and the third argument is a numeric format code. Here we indicate that we wish to display three digits after the decimal. Table TAB1 will contain the reformatted output:
